<?php

namespace JLPay\Services\Openmerch\Alipay;

use JLPay\Services\BaseService;
use JLPay\Models\Openmerch\Alipay\RealnameAliQueryRequest;
use JLPay\Models\Openmerch\Alipay\RealnameAliQueryResponse;

/**
 * 开放商户支付宝服务
 */
class AlipayService extends BaseService
{
    /**
     * 构造函数
     *
     * @param \JLPay\Core\OrgConfig $config
     */
    public function __construct($config)
    {
        parent::__construct($config);
    }

    /**
     * 获取API URL
     *
     * @param string $requestClass
     * @param string|null $apiPath
     * @return string
     */
    public function getApiUrl(string $requestClass, ?string $apiPath = null): string
    {
        $baseUrl = $this->config->getUrl();
        
        if ($apiPath) {
            return $baseUrl . $apiPath;
        }
        
        // 直接使用Request类中定义的完整API路径
        $apiUrl = constant($requestClass . '::API_URL');
        
        if (!$apiUrl) {
            // 如果没有定义API_URL，使用默认路径
            return $baseUrl . '/open/merch/access/alipay';
        }
        
        // 直接返回完整路径
        return $baseUrl . $apiUrl;
    }

    /**
     * 查询支付宝实名认证信息
     *
     * @param RealnameAliQueryRequest $request
     * @return RealnameAliQueryResponse
     */
    public function queryRealnameAli(RealnameAliQueryRequest $request): RealnameAliQueryResponse
    {
        return $this->post($request, RealnameAliQueryResponse::class);
    }
} 